<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport"
	content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<script src="${pageContext.request.contextPath}/js/echarts.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery-2.min.js"></script>
<link href="${pageContext.request.contextPath}/css/mui.min.css" rel="stylesheet" />
<link href="${pageContext.request.contextPath}/css/new.style.css" rel="stylesheet" />
<link href="${pageContext.request.contextPath}/css/common.css" rel="stylesheet" />
<style>
			.mui-input-group {
				margin-top: 30px;
			}
			.mui-content-padded{
			    margin-top: 30px;
			}
</style>
<title>验证您的身份</title>
</head>
<body>
        <header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">登录</h1>
		</header>
		<div class="mui-content page_reg">
		<div class="form_userinfo mui-input-group">
				<div class="mui-input-row">
					<label>手机号</label>
					<input type="text" class="mui-input" id="phone" name="phone" onfocus="this.value=''" placeholder="请输入手机号">
				</div>
				<div class="mui-input-row"  style="position:relative">
					<label>验证码</label>
					<input  type="text" class="mui-input" id="phoneCode" name="phoneCode" onfocus="this.value=''" placeholder="请输入验证码">
					<input class="code_btn_get" id="sendPhoneCode" value="获取验证码" onclick="send_phone_code(this)"/>
				</div>
		</div>
				<div class="mui-content-padded">
					<button id='submitBtn' class="mui-btn mui-btn-block mui-btn-primary">登录</button>
				</div>
				</div>
		<input type="hidden" id="Consumer_HistoryCacheId"
			name="Consumer_HistoryCacheId" value="${message}">
</body>
<script type="text/javascript">
    var wait = 60;//倒计时60秒
    var intervalId;//定时
    var i = wait;//倒计时递减 1
    function exit() {
        $("#sendPhoneCode").val(i + "秒后重新发送").addClass("disabled");
        i = i - 1;
        if (i <= -1) {
            clearInterval(intervalId);
            $("#sendPhoneCode").removeAttr("disabled");
            $("#sendPhoneCode").val("获取验证码").removeClass("disabled");
        }
    }
    function send_phone_code() {

        var phone = $("#phone").val();
        if (phone == '') {
            alert('请输入手机号', '系统提示', function() {
                $('#phone').focus();
            });
            return false;
        }
        if(phone.length==0) 
	       { 
	          alert('请输入手机号码！'); 
	          $('#phone').focus() 
	          return false; 
	       }     
	       if(phone.length!=11) 
	       { 
	           alert('请输入有效的手机号码！'); 
	           $('#phone').focus()
	           return false; 
	       } 
        if (!phone.match(/^1[3|4|5|7|8][0-9]{9}$/)) {
            alert('请输入正确的手机号', '系统提示', function() {
                $('#phone').focus();
            });
            return false;
        }

        i = wait;
        $("#sendPhoneCode").attr("disabled", "disabled");
        $("#sendPhoneCode").val("发送成功");
        intervalId = setInterval("exit()", 1000);
        $.ajax({
        	type : "post",
			url : "${pageContext.request.contextPath}/Consumer/SendPhoneCode",
			//url:"http://localhost:80/CdSystem2.0/Consumer/SendPhoneCode",
			data : {
				Phone : phone
			},
			success : function(data) {
			},
        }).responseText;
    }
	(function($) {
		$(document)
				.ready(
						function() {
							$("#submitBtn")
									.click(
											function() {
												var obj = $(this);
												var Phone = $("#phone").val();
												var PhoneCode = $("#phoneCode")
														.val();
												var consumer_HistoryCacheId = $(
														"#Consumer_HistoryCacheId")
														.val();
												if (Phone == '') {
													alert("手机号码不能为空");
													return false;
												}
												if (PhoneCode == '') {
													alert("验证码不能为空");
													return false;
												}
												$.ajax({
															url : "${pageContext.request.contextPath}/Consumer/BindConsumerAndRecord",
															type : "POST",
															data : {
																phone : Phone,
																phoneCode : PhoneCode,
																Consumer_HistoryCacheId : consumer_HistoryCacheId
															},
															dataType : "json",
															success : function(
																	result) {
																if (result.message == 'success') {
																	$.ajax({
																		type : "post",
																		url : "${pageContext.request.contextPath}/Consumer/ShowConsumerTestResult",
																		data:{Consumer_HistoryCacheId:consumer_HistoryCacheId},
																		dataType:"json",
																		success:function(result){
																		if(result.errorMessage=='success'){
																			var form = $("<form></form>");  
																		    form.attr('action', "http://www.huajiu.cc:8081/weixin_project/jsp/solutionView/ConsumerTestResult.jsp");  
																		    form.attr('method', 'post');  
																		    form.attr('target', '_self');  
																		    var input1 = $("<input type='hidden' id='Consumer_HistoryCacheId' name='Consumer_HistoryCacheId' />");
																		    input1.attr('value',consumer_HistoryCacheId);  
																		    form.append(input1);  
																		    form.appendTo("body");  
																		    form.css('display', 'none');  
																		    form.submit();  
																		}
																		else if(result.errorMessage=='not pay'){
																			 	var form = $("<form></form>");  
																			    form.attr('action', "${pageContext.request.contextPath}/jsp/wxPay.jsp");  
																			    form.attr('method', 'post');  
																			    form.attr('target', '_self');  
																			    var input1 = $("<input type='hidden' name='Consumer_HistoryCacheId' />");  
																			    input1.attr('value',consumer_HistoryCacheId);  
																			    form.append(input1);  
																			    form.appendTo("body");  
																			    form.css('display', 'none');  
																			    form.submit();  
																		}
																					
																		},
																	}).responseText;
																	
																} else {
																	alert(result.message);
																}
															},
															error : function(
																	XMLHttpRequest,
																	textStatus,
																	errorThrown) {
																alert(XMLHttpRequest.status);
																alert(XMLHttpRequest.readyState);
																alert(textStatus);
															}
														})
												return false;
											})
						});
	})(jQuery);
	
	
</script>
</html>